#include<bits/stdc++.h>
using namespace std;

int T, n,maxn;
int number[200005];
bool color[200005];
void dfs(int dep,int score){
    if(dep>n){
        maxn = max(maxn, score);
    }
    else{
        color[dep] = 0;
        int ds = 0;
        for (int i = dep - 1; i > 0; i--){
            if(color[i]==0){
                ds = (number[i] == number[dep]) ? number[dep] : 0;
                break;
            }
        }
        dfs(dep + 1, score + ds);

        color[dep] = 1;
        ds = 0;
        for (int i = dep - 1; i > 0; i--){
            if(color[i]==1){
                ds = (number[i] == number[dep]) ? number[dep] : 0;
                break;
            }
        }
        dfs(dep + 1, score + ds);
        
    }
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);

    cin >> T;
    for (int o = 1;o <= T;o++){
        maxn = -1;
        cin >> n;
        for (int i = 1; i <= n;i++){
            cin >> number[i];
        }
        dfs(1,0);
        cout << maxn << endl;
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}